<?php
/*
Simple:Press Forum
Template Tag(s) - Linked Topics as Comments
$LastChangedDate: 2009-10-17 04:59:43 +0100 (Sat, 17 Oct 2009) $
$Rev: 2832 $
*/

if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
	die('Access Denied');
}

/* 	=====================================================================================

	sf_comments_number($no_comment="0 Comments", $one_comment="1 Comment", $many_comment="% Comments", $blogcomments)

	Replaces the WP Template Tag: comments_number()
	Supplies Count of topic posts and can optionally include the standard blog comments in the total

	parameters:

		$no_comment		Used for zero comments			text
		$one_comment	Used for one comment			text
		$many_comment	Used for multiple comments		text
		$blogcomments	Include Standard Blog Comments (true or false)
 	===================================================================================*/

function sf_comments_number($no_comment="0 Comments", $one_comment="1 Comment", $many_comment="% Comments", $blogcomments=false)
{
	global $wp_query;

	sf_initialise_globals();

	$result = $no_comment;
	$total = 0;
	$postid = $wp_query->post->ID;
	$links = sf_blog_links_control('read', $postid);

	# If linked get the post count (-1 of course)
    if ($links && sf_can_view_forum($links->forum_id))
	{
		# link found for this post
		$total = (sf_get_posts_count_in_linked_topic($links->topic_id) -1);
	}

	# If to include standard blog comments add that number
	if($blogcomments)
	{
		$total = ($total + $wp_query->post->comment_count);
	}

	if($total > 0)
	{
		if($total == 1 ? $result=$one_comment : $result=str_replace('%', $total, $many_comment));
	}
	echo $result;

	return;
}

?>